package com.bocloud.cmp.driver.providers.impl;

import org.springframework.stereotype.Service;

import com.bocloud.cmp.driver.config.Configuration;
import com.bocloud.cmp.driver.providers.FirewallDriver;
import com.bocloud.cmp.driver.providers.intf.FirewallProvider;
import com.bocloud.cmp.driver.providers.jd.JdFirewallDriver;
import com.bocloud.cmp.driver.utils.VendorConverter;
import com.bocloud.cmp.enums.VendorType;
import com.bocloud.cmp.model.Butler;
import com.bocloud.cmp.model.FirewallModel;
import com.bocloud.common.model.BsmResult;

@Service("firewallProvider")
public class FirewallProviderImpl implements FirewallProvider {

	@Override
	public BsmResult list(String vendor, String region) {
		BsmResult result = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case JDYUN:
			FirewallDriver driver = new JdFirewallDriver(butler.getAccessKey(), butler.getSecretKey(), butler.getUrl(),
					region);
			result = driver.list();
			break;
		case ALIYUN:
			break;
		case OPENSTACK:
			break;
		case VMWARE:
			break;
		default:
			break;
		}
		return result;
	}

	@Override
	public BsmResult create(String vendor, String region, FirewallModel firewall) {
		BsmResult result = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case JDYUN:
			FirewallDriver driver = new JdFirewallDriver(butler.getAccessKey(), butler.getSecretKey(), butler.getUrl(),
					region);
			result = driver.create(firewall);
			break;
		case ALIYUN:
			break;
		case OPENSTACK:
			break;
		case VMWARE:
			break;
		default:
			break;
		}
		return result;
	}

	@Override
	public BsmResult remove(String firewallId, String vendor, String region) {
		BsmResult result = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case JDYUN:
			JdFirewallDriver driver = new JdFirewallDriver(butler.getAccessKey(), butler.getSecretKey(),
					butler.getUrl(), region);
			result = driver.remove(firewallId);
			break;
		case ALIYUN:
			break;
		case OPENSTACK:
			break;
		case VMWARE:
			break;
		default:
			break;
		}
		return result;
	}

	@Override
	public BsmResult detail(String firewallId, String vendor, String region) {
		BsmResult result = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case JDYUN:
			FirewallDriver driver = new JdFirewallDriver(butler.getAccessKey(), butler.getSecretKey(), butler.getUrl(),
					region);
			result = driver.detail(firewallId);
			break;
		case ALIYUN:
			break;
		case OPENSTACK:
			break;
		case VMWARE:
			break;
		default:
			break;
		}
		return result;
	}

}
